home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / BARNET / FREENET / FERGUSON / CLIENT_P / !Client_Ex / c / Client_Ex < prev    next >
Text File  |  1995-06-04  |  6KB  |  218 lines

  1. /*
  2.   File:    Client_Ex.c
  3.   Author:  © 1993 &1994 by Duncan Ferguson
  4.   Version: v0.01 22-Jan-1995
  5.   Purpose: Basic C application template
  6. */
  7.  
  8. /* ============================================================= */
  9. /* |                   Include files               | */
  10. /* ============================================================= */
  11. #include "ProgInfo.h"
  12.  
  13. #include "Address.h"
  14. #include "Connect.h"
  15. #include "Command.h"
  16.  
  17. #include "DeskLib:Error.h"
  18. #include "DeskLib:Event.h"
  19. #include "DeskLib:EventMsg.h"
  20. #include "DeskLib:Handler.h"
  21. #include "DeskLib:Icon.h"
  22. #include "DeskLib:Resource.h"
  23. #include "DeskLib:Menu.h"
  24. #include "DeskLib:Msgs.h"
  25. #include "DeskLib:Screen.h"
  26. #include "DeskLib:Template.h"
  27. #include "DeskLib:WIMP.h"
  28. #include "DeskLib:WimpSWIs.h"
  29. #include "DeskLib:Window.h"
  30.  
  31. #include <assert.h>
  32. #include <stdio.h>
  33. #include <stdlib.h>
  34. #include <string.h>
  35.  
  36. /* ============================================================= */
  37. /* |                       #Definitions                        | */
  38. /* ============================================================= */
  39. #define NEVER_REACH_HERE FALSE
  40.  
  41. /* ============================================================= */
  42. /* |                     Structures                            | */
  43. /* ============================================================= */
  44. enum {
  45.   iconmenu_INFORMATION,
  46.   iconmenu_QUIT
  47. };
  48.  
  49. enum {
  50.     proginfo_NAME = 1,
  51.     proginfo_AUTHOR,
  52.     proginfo_PURPOSE,
  53.     proginfo_VERSION
  54. };
  55.  
  56. enum {
  57.   ApplicationNameLength = 64,
  58.   ApplicationPurposeLength = 64,
  59.   ApplicationVersionLength = 30,
  60.   ApplicationMenuLength = 260
  61. };
  62.  
  63. /* ============================================================= */
  64. /* |                Global variables               | */
  65. /* ============================================================= */
  66.  
  67. /* Window and menu handles */
  68. static menu_ptr       Icon_Menu       = NULL;
  69. static icon_handle    Bar_Icon       = 0;
  70. static window_handle  Prog_Info    = 0;
  71.  
  72. /* menu variables needd */
  73. static BOOL Quit = FALSE;
  74.  
  75. /* ============================================================= */
  76. /* |                    Function Prototypes                    | */
  77. /* ============================================================= */
  78. static BOOL    IconBarMenuChoice(    event_pollblock *event, void *reference);
  79. static BOOL    IconBarClick(         event_pollblock *event, void *reference);
  80. static BOOL    UserMessage(          event_pollblock *event, void *reference);
  81. static BOOL    DataLoad_Message(     event_pollblock *event, void *reference);
  82.  
  83. /* ============================================================= */
  84. /* |                    External functions                     | */
  85. /* ============================================================= */
  86.  
  87. int main(int argc, char *argv[])
  88. {
  89.   char     ApplicationName[ApplicationNameLength+1];
  90.   char     ApplicationPurpose[ApplicationPurposeLength+1];
  91.   char     ApplicationVersion[ApplicationVersionLength+1];
  92.   char     MenuDescription[ApplicationMenuLength+1];
  93.   const unsigned int RiscVersion = 310;
  94.  
  95.   UNUSED(argc);
  96.   UNUSED(argv);
  97.  
  98.   Resource_Initialise("Client_Ex");
  99.  
  100.   if(!Msgs_LoadFile("Resources.Messages"))
  101.   {
  102.     Error_ReportFatal(1, "Resources could not be found");
  103.   }
  104.  
  105.   Msgs_Lookup("app.name", ApplicationName, ApplicationNameLength);
  106.  
  107.   Event_Initialise3(ApplicationName, RiscVersion, NULL);
  108.   EventMsg_Initialise();
  109.  
  110.   Screen_CacheModeInfo();
  111.   EventMsg_Claim(message_MODECHANGE, event_ANY, Handler_ModeChange, NULL);
  112.  
  113.   Template_Initialise();
  114.   Template_UseOutlineFonts();
  115.   Template_LoadFile("Resources.Templates");
  116.  
  117.   Msgs_Lookup("app.purpose",ApplicationPurpose, ApplicationPurposeLength);
  118.   Msgs_Lookup("app.version:0.00",ApplicationVersion, ApplicationVersionLength);
  119.   strcat(ApplicationVersion, DATE);
  120.  
  121.   Prog_Info = Window_Create("ProgInfo", 0);
  122.   Icon_SetText(Prog_Info, proginfo_NAME, ApplicationName);
  123.   Icon_SetText(Prog_Info, proginfo_AUTHOR, ApplicationPurpose);
  124.   Icon_SetText(Prog_Info, proginfo_PURPOSE, AUTHOR);
  125.   Icon_SetText(Prog_Info, proginfo_VERSION, ApplicationVersion);
  126.  
  127.   Msgs_Lookup("app.mainmenu", MenuDescription, ApplicationMenuLength);
  128.   Icon_Menu = Menu_New(ApplicationName, MenuDescription);
  129.  
  130.   Menu_AddSubMenu(Icon_Menu, iconmenu_INFORMATION, (menu_ptr)Prog_Info);
  131.  
  132.   Event_Claim(event_OPEN,  event_ANY,  event_ANY, Handler_OpenWindow, NULL);
  133.   Event_Claim(event_CLICK, event_ANY,  event_ANY, IconBarClick,       NULL);
  134.   Event_Claim(event_MENU,  event_ANY,  event_ANY, IconBarMenuChoice,  NULL);
  135.  
  136.   setbuf(stderr, NULL);
  137.   setbuf(stdout, NULL);
  138.  
  139.   if(Connect_Initialise())
  140.   {
  141.     /* put icon on icon bar here so icon bar doesnt flicker if failed */
  142.     Bar_Icon = Icon_BarIcon(ApplicationName, iconbar_RIGHT);
  143.     Address_ContactServer();
  144.     Command_Open();
  145.   }
  146.   else
  147.   {
  148. /* Error messages are given within connect module for the problem */
  149.     Quit = TRUE;
  150.   }
  151.  
  152.   while(!Quit)
  153.   {
  154.     Connect_WimpPoll();
  155.   }
  156.  
  157.   Connect_Shutdown();
  158.  
  159.   return FALSE;
  160. }
  161.  
  162. extern Client_Ex_RequestQuit(void)
  163. {
  164.   Quit = TRUE;
  165. }
  166.  
  167. /* ============================================================= */
  168. /* |                  Internal functions                       | */
  169. /* ============================================================= */
  170.  
  171. static BOOL IconBarMenuChoice(event_pollblock *event, void *reference)
  172. {
  173.   mouse_block ptr;
  174.  
  175.   UNUSED(reference);
  176.  
  177.   if(menu_currentopen != Icon_Menu) return FALSE;
  178.  
  179.   switch(event->data.selection[0])
  180.   {
  181.     case iconmenu_INFORMATION:
  182.       break;
  183.  
  184.     case iconmenu_QUIT:
  185.       Quit = TRUE;
  186.       break;
  187.  
  188.     default:
  189.       assert(NEVER_REACH_HERE);
  190.       break;
  191.   }
  192.  
  193.   Wimp_GetPointerInfo(&ptr);
  194.  
  195.   if(ptr.button.data.adjust) Menu_ShowLast();
  196.  
  197.   return TRUE;
  198. }
  199.  
  200. static BOOL IconBarClick(event_pollblock *event, void *reference)
  201. {
  202.   int ypos = -1;
  203.  
  204.   UNUSED(reference);
  205.  
  206.   if(event->data.mouse.button.data.menu)
  207.   {
  208.     Menu_Show(Icon_Menu, event->data.mouse.pos.x, ypos);
  209.   }
  210.  
  211.   if(event->data.mouse.button.data.select)
  212.   {
  213.     Command_Open();
  214.   }
  215.  
  216.   return TRUE;
  217. }
  218.